//
//  LoginManager.m
//  DogeLegs
//
//  Created by 宋华 on 2017/8/18.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "LoginManager.h"
#import "NetRequest+user.h"
#import "UserManager.h"

@implementation LoginManager

+ (LoginManager *)sharedInstance
{
    static dispatch_once_t onceBasicToken;
    
    static LoginManager *loginManager = nil;
    
    dispatch_once(&onceBasicToken, ^{
        loginManager = [[LoginManager alloc] init];
    });
    return loginManager;
}


- (NSURLSessionDataTask *)loginDictorany:(NSDictionary *)parmas success:(LoginSuccessBlock)success failed:(LoginFailedBlock)failedBlock {
    NSString *emailAddress = parmas[LOGIN_EmailAddress];
    NSString *pwd = parmas[LOGIN_PASSWord];

    NSURLSessionDataTask *dataTask = [[NetRequest sharedInstance] loginDictionary:[NSDictionary dictionary] success:^(UserMode *user) {
        user.userName = emailAddress;
        user.password = pwd;
        [[UserManager shareInstance] saveUserLoginInfo:user];
        //登陆成功保存用户名密码
        [[UserManager shareInstance] loginSuccess:emailAddress password:pwd];
        if (success) {
            success(user);
        }
    } fail:^(RequestError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
    return dataTask;
}

@end
